/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-03-20 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#ifndef EXCEPTION_H_INCLUDED
#define EXCEPTION_H_INCLUDED

#define EXCEPTION_TYPEID 6

typedef struct Exception Exception;
typedef struct ExceptionInterface ExceptionInterface;
typedef struct ExceptionVirtualTable ExceptionVirtualTable;

#include "Class.h"
#include "String.h"

struct ExceptionVirtualTable
{
    unsigned long int TypeID;
    ExceptionInterface* Interface;
    ClassVirtualTable* AncestorTable;
    unsigned long int ReferenceCount;
    Exception* (*new)(unsigned long pArgsCount, va_list* pParameters);
    ExceptionVirtualTable* (*Initialize)(Exception* this, unsigned long pArgsCount, va_list* pParameters);
    void (*Garbage)(Exception* this);
    unsigned long int (*TypeOf)(Exception* this);
    bool (*IsSameTypeThanTypeID)(Exception* this, unsigned long int pTypeID);
    bool (*IsKindOfTypeID)(Exception* this, unsigned long int pTypeID);
    bool (*IsSameTypeThan)(Exception* this, Class* pSource);
    bool (*IsKindOf)(Exception* this, Class* pSource);
};

struct ExceptionInterface
{
    void (*Constructor)(Exception* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(Exception* this);
    Exception* (*Clone)(Exception* this);
    const Exception* const (*PreviousException)(Exception* this);
    const String* const (*Message)(Exception* this);
};

struct Exception
{
    ExceptionVirtualTable* VirtualTable;
    void (*Constructor)(Exception* this, unsigned long int pArgsCount, va_list* pParameters);
    void (*Destructor)(Exception* this);
    Exception* (*Clone)(Exception* this);
    Exception* aPreviousException;
    String* aMessage;
    const Exception* const (*PreviousException)(Exception* this);
    const String* const (*Message)(Exception* this);
};

Exception* ExceptionNew(unsigned long pArgsCount, va_list* pParameters);
ExceptionVirtualTable* ExceptionInitialize(Exception* this, unsigned long pArgsCount, va_list* pParameters);
unsigned long int ExceptionTypeOf(Exception* this);
void ExceptionConstructor(Exception* this, unsigned long int pArgsCount, va_list* pParameters); /* Constructor pointer of object. Called by Initialise(). Must be propagated on inherited that do not override.*/
void ExceptionDestructor(Exception* this); /* Destructor pointer of object. Called by Garbage(). Must be propagated on inherited that do not override.*/
Exception* ExceptionClone(Exception* this);
const Exception* const ExceptionPreviousException(Exception* this);
const String* const ExceptionMessage(Exception* this);
#endif /* EXCEPTION_H_INCLUDED*/
